package org.shj.basic;

public class VolatileDemo {

	//private static boolean done; //线程没有正确终止
	private static volatile boolean done; //线程可以正确终止
	
	public static void main(String[] args) throws Exception{
		new Thread(new Runnable(){
			public void run(){
				int i = 0;
				while(!done){
					i++;
				}
				System.out.println("Done when i = " + i);
			}
		}).start();
		
		System.out.println("OS: " + System.getProperty("os.name"));
		Thread.sleep(2000);
		done = true;
		System.out.println("flag done set to true");
		
		double i = 0.0;
		double b = 3/i;
		System.out.println(b); // 输出 Infinity，没抛错 !!!
				
				
	}
}
